<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .show {}

        .hide {
            display: none;
        }
    </style>
</head>

<body>
    <button id="sel" class="show" onclick="allInput()">全选</button>
    <button id="nosel" class="hide" onclick="cancelAll()">取消全选</button>
    <table id="tab">
        <tbody id="tb">
            <tr>
                <td>
                    <input class="checkbox" type="checkbox">
                </td>
                <td>鸡</td>
                <td><button onclick="deltr(0)">删除</button></td>
            </tr>
            <tr>
                <td>
                    <input class="checkbox" type="checkbox">
                </td>
                <td>你</td>
                <td><button onclick="deltr(1)">删除</button></td>
            </tr>
            <tr>
                <td>
                    <input class="checkbox" type="checkbox">
                </td>
                <td>太美</td>
                <td><button onclick="deltr(2)">删除</button></td>
            </tr>
        </tbody>
        <button onclick="addTr()">添加行</button>
    </table>
</body>
<script>
    function allInput() {
        var ins = document.getElementsByClassName("checkbox");
        for (let i = 0; i < ins.length; i++) {
            ins[i].setAttribute("checked", "true"); 
        }
        document.getElementById("sel").setAttribute("class", "hide")
        document.getElementById("nosel").setAttribute("class", "show")
    }
    function cancelAll() {
        var ins = document.getElementsByClassName("checkbox");
        for (let i = 0; i < ins.length; i++) {
            ins[i].removeAttribute("checked")  
        }
        document.getElementById("sel").setAttribute("class", "show")
        document.getElementById("nosel").setAttribute("class", "hide")
    }
    function deltr(idx) {
        var tb = document.getElementById("tb")
        var trs = document.getElementsByTagName("tr")
        tb.removeChild(trs[idx])
    }
    function addTr() {
        var tb = document.getElementById("tb")
        var trs = document.getElementsByTagName("tr")
        var str_tr = '<tr><td><input class="checkbox" type="checkbox"></td><td>商品' + (trs.length + 1) + '其他信息</td><td><button onclick="deltr(' + trs.length + ')">删除</button></td></tr>';
        tb.innerHTML = tb.innerHTML + str_tr;
    }

</script>

</html>